/**
 * User: yangxiul
 * Date: 16-8-18
 * Time: 上午9:04
 * 土地拓展过程管控统计报表
 */

 
define("require dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/fx dojo/fx/easing ../../util/ajaxUtil dojo/dom dojo/dom-attr dojo/dom-class dojo/dom-style dojo/on dojo/query dojo/topic ../BaseWidget esri/symbols/SimpleFillSymbol esri/symbols/SimpleLineSymbol esri/graphic esri/layers/GraphicsLayer esri/Color esri/SpatialReference esri/geometry/Point gistech/util/infoUtil dojo/text!./templates/Template.html".split(" "),
    function (require, declare, lang, array, baseFx,easing,ajaxUtil, dom, domAttr, domClass, domStyle, on, query, topic, BaseWidget,SimpleFillSymbol,SimpleLineSymbol,Graphic,GraphicsLayer,Color,SpatialReference,Point,infoUtil,template) {
 

        return declare([BaseWidget], {
            templateString: template,
            map: null,
            rightTab:null,
            ismove:false,//组件位置移动判断
            grouplist:null,
            projectlist:null,
            selectType:"1",//1为城市，2为行政区
            projectType:"mocha",
            orgFields:null,
            
            reportstarttime:null,
            reportendtime:null,
            
            currentDataList:null,
            
            OrganizationList:null,
            
            companyList:[],
            departmentList:[],
            teamGroupList:[],
            
            landareaGraphicLayer:null,
            constructor: function (args) {
                this.map = args.map;
                this.rightTab = args.rightTab;
            },

            postCreate: function () {
            	this.inherited(arguments);
    			this.areaSelectClick();
    			on(this.area, "change",lang.hitch(this,this.areaSelectClick));
    			on(this.quyuBtn, "click",lang.hitch(this,this.quyuBtnClick));
    			on(this.specialExportBtn, "click",lang.hitch(this,this.exportBtnClick));
    			on(this.closebtn2,"click",lang.hitch(this,this.closeDialog));
            },

            startup: function () {
                this.inherited(arguments);
            },
            
            areaSelectClick:function(){
//            	alert('1')
            	var cityName = this.area.value;
            	var type = this.selectType;
 
                ajaxUtil.request("../client/service/specialdataController/queryAreaOrDistinct","type="+type+"&cityName="+cityName,lang.hitch(this,function(result){
                    var Store = eval(result.result);
                     var StoreHTML = "<option selected=\"selected\" value=\"\">请选择</option>";
                     for(var i=0; i<Store.length;i++){
                         StoreHTML += "<option value='"+Store[i].RESULTDATA+"'>"+Store[i].RESULTDATA+"</option>";
                     }
                     if(type==1){//城市
                    	 this.area.innerHTML = StoreHTML;
                     }else if(type==2){//行政区
                    	 this.distinct.innerHTML = StoreHTML;
                     } 
                    if(this.selectType=='1'){
                    	this.selectType='2';
                    }	 
                    
                 }),function(){
                    console.error("获取下拉列表失败");
                 });
            },
            
            quyuBtnClick:function(){
            	var areaValue = this.area.value;
            	var distinctValue = this.distinct.value;
            	var jcfCheck = this.jcfCheckbox.checked;//旧厂房
            	var lydCheck = this.lydCheckbox.checked;//留用地
            	var condition = "cityName="+areaValue+"&distinctName="+distinctValue;
            	var checkCondition="&type=";
            	if(jcfCheck){
            		checkCondition+="jcf:";
            	}
            	if(lydCheck){
            		checkCondition+="lyd:";
            	}            	
            	condition+=checkCondition;
                ajaxUtil.request("../client/service/specialdataController/querySpecialdataList",condition,lang.hitch(this,function(result){
                	this._inittable(result)
                 }),function(){
                    console.error("获取专题数据报表数据失败");
                 });
            },
            
            /*
             * 初始化表头
             */
            _inittableHeader:function(){
            	return '<tr align="center" class="specialTr"><tr><th rowspan="2" width="40">序号</th><th rowspan="2" width="80">行政区</th><th colspan="2" width="115">旧厂房</th><th colspan="2" width="115">留用地</th></tr><tr><th >宗数</th><th >面积</th><th >宗数</th><th >面积</th></tr></tr>';
            },
            
            /*
             * 初始化表格
             */
            _inittable:function(source ){
            	
            	this.specialDataReport.innerHTML="";
                var html="";
            	var headerHtml=this._inittableHeader();
            	html+=headerHtml;
            	var num = 0;
                var Store = eval(source.result);
             	for (var i=0;i<Store.length;i++){
        			var data=Store[i]; 
        			html+="<tr><td>"+(++num)+' </td><td>'+data.FQMC+'</td><td>'+data.JCFCOUNT+'</br><td>'+data.JCFAREASUM+'</td><td>'+data.LYDCOUNT+'</td><td>'+data.LYDAREASUM+'</td>';
        			html+="</tr>";//style="display:nono"
        		}
            	html=html.replace(/undefined/g,'');
            	this.specialDataReport.innerHTML=html;
            },
 
            
            exportBtnClick:function(){
            	var areaValue = this.area.value;
            	var distinctValue = this.distinct.value;
            	var condition = "cityName="+areaValue+"&distinctName="+distinctValue;
				var form = this.specialExportForm;
				form.action="../client/service/specialdataController/exportSpecialdataExcel?"+condition;
			    form.submit();
			    form.remove();
            },
 
            closeDialog:function(){
     			this.inherited("closeDialog",arguments);
     			this.rightTab.expandBtn.click();
     			this.destroy();
     		},
            destroy: function () {
                var widgets = this.widgets;
                for (var name in widgets) {
                    if (widgets[name]) {
                        widgets[name].destroy();
                    }
                }
                this.inherited(arguments);
            },
      
        });
    });